<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/base/taglibs.jsp"%>
<%@include file="/WEB-INF/jsp/base/head.jsp"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色权限管理</title>
</head>
<body>
	<s:form id="form1" namespace="/system" action="roleAction!getRoleAuth.do" name="form1" method="post">
	<div class="center_main">
		<div id="btn-option">
			<b style="margin-left: 12px;">当前角色：</b><s:select id="roleId" cssStyle="margin-top: -4px;" list="roleBizBeanList" listKey="id" listValue="roleName" name="roleId" value="roleId" onchange="getRoleAuth();"></s:select>
			<a class="add-btn" onclick="chooseAuth();" href="javascript:void(0);" title="新增权限">新增权限</a>
			<a class="del-btn" id="deleteAuth" href="javascript:void(0);" title="删除">删除</a>
			<a class="back-btn" onclick="javascript:window.location='<%=request.getContextPath()%>/system/roleAction!getRoleList.do';" href="javascript:void(0);" title="返回">返回</a>
		</div>
		<div class="center_left"></div>
	</div>

	<div id="page-top">
		<span>角色权限管理列表</span>
		<b></b><i></i>
	</div>
  
	<div id="page"> 
    	<input name="roleBizBean.authIds" type="hidden" id="ids"/>
      		<!-- 
           <div id="search"> </div>
		
		<div id="search-btn-wapper">
		
		</div>
            -->
           <div id="item-list">
			<table>
			   <thead>
			     <tr>
					<th>选择<input type="checkbox" id="selectAll" /></th>
					<th>序号</th>
					<th>权限名称</th>
					<th>权限描述</th>
				 </tr>
			   </thead>
			   <tbody>
			   
					<s:iterator value="authList" var="r" status="sta"> 
					<tr>
						<td><input type="checkbox" name="authIds" class="classCheckbox" value='<s:property value="#r.id"/>' /></td>
						<td><s:property value="#sta.index+1"/></td>
						<td><s:property value="#r.name"/></td>
						<td><s:property value="#r.description"/></td>
					</tr>
					</s:iterator>
					
					<s:if test="authList.size == 0">
					    <tr>
					       <td colspan="4">数据暂无!</td>
					    </tr>
					</s:if>
				</tbody>
			</table>
		</div>
   	</div>
    <div id="page-bottom">
    	<b></b><i></i>
    </div>
	</s:form>
</body>
<script type="text/javascript">
$(function(){
	$("#deleteAuth").click(function(){
		deleteRoleAuth();
	});
});

var deleteRoleAuth = function(){
	var authIds = $("input[name='authIds']:checked");	
	var ids = "";
	if(null != authIds  && authIds.length > 0){
		authIds.each(function(){
			ids +=$(this).val()+ ",";
		});
		if(ids != ""){
			$("#ids").val(ids.substring(0, ids.length-1));	
			if(confirm("您，确定要删除选中的数据？")){
				$("#form1").attr("action","system/roleAction!deleteRoleAuth.do");
				$("#form1").submit();
			}
		}
	} else {
		alert("您，还没有选择数据！");
	}
};

var chooseAuth = function(){
	var roleId = document.getElementById("roleId").value;
	var result = window.showModalDialog('<%=request.getContextPath()%>/system/roleAction!getNotRoleAuth.do?roleId='+ roleId,null,'dialogWidth:900px; dialogHeight:450px; center:yes;scroll:no;resizable:yes');
	if(window.ReturnValue != null && window.ReturnValue.length > 0) {
		result = window.ReturnValue;
	}
	if(result != null && result != "") {
	 	window.location.href="<%=request.getContextPath()%>/system/roleAction!saveRoleAuth.do?roleBizBean.authIds=" + result +"&roleId=" + roleId;
	}
};

var getRoleAuth = function() {
	var roleId = document.getElementById("roleId").value;
	window.location.href="<%=request.getContextPath()%>/system/roleAction!getRoleAuth.do?roleId=" + roleId;
};
</script>
</html>